package com.cwd.arm.application.service.read;

import com.cwd.arm.infrastructure.dao.TaxDao;
import com.cwd.arm.infrastructure.po.TaxPo;
import com.cwd.arm.application.dto.TaxDto;
import com.cwd.arm.application.service.read.facade.TaxReadService;
import com.cwd.arm.infrastructure.query.TaxDaoQuery;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Description:开票信息
 * Created on 2021年11月16日
 *
 * @author yan
 */
@Repository
@Primary
public class TaxReadServiceImpl implements TaxReadService {

    @Autowired
    private TaxDao taxDao;

    @Override
    public TaxDto selectById(Long id) {
        return convertToDto(taxDao.getById(id));
    }

    @Override
    public List<TaxDto> selectByProjectId(Long projectId) {
        TaxDaoQuery taxDaoQuery = new TaxDaoQuery();
        taxDaoQuery.setProjectId(projectId);
        return selectByQuery(taxDaoQuery);
    }

    @Override
    public List<TaxDto> selectByQuery(TaxDaoQuery taxDaoQuery) {
        return convertToDtoList(taxDao.selectByQuery(taxDaoQuery));
    }

    private TaxDto convertToDto(TaxPo po) {
        TaxDto dto = new TaxDto();
        BeanUtils.copyProperties(po, dto);
        return dto;
    }

    private List<TaxDto> convertToDtoList(List<TaxPo> poList) {
        return poList.stream().map(po -> (convertToDto(po))).collect(Collectors.toList());
    }

}
